$package('itsm.news');

itsm.news.addNews=function(){
	
	return {
		changeCategory:function(topicId){
			$.post('category!findCategoryPager.action','rows=10000&categoryDTO.topicId='+topicId,function(result){
				$('#addNews_category').html('');
				var data = result.data;
				for(var i=0;i<data.length;i++){
					$('<option value="'+data[i].categoryId+'">'+data[i].categoryName+'</option>').appendTo('#addNews_category');
				}
					
			});
		},
		//加载栏目
		loadTopicOption:function(select,type){
			$.post('topic!findTopicPager.action','rows=10000',function(result){
				$(select).html('');
				var data = result.data;
				if(type=='selectNull'){
					$('<option value="">--请选择-- </option>').appendTo(select);
				}
				for(var i=0;i<data.length;i++){
					if(i==0)
						itsm.news.addNews.changeCategory(data[i].topicId)
					
					$('<option value="'+data[i].topicId+'">'+data[i].topicName+'</option>').appendTo(select);
				}
					
			});
		},
		//保存
		saveNews:function(){
			if($('#add_news').form('validate')){
//				var oEditor = CKEDITOR.instances.addNews_content;
				var _param = $('#add_news form').serialize();
				$.post('news!saveNews.action',_param,function(data){
					msgShow('保存成功!','show');
					itsm.common.utility.tabUtility.closeTab('新增内容');
					$('#newsMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		init:function(){
			//itsm.news.addNews.loadTopicOption('#addNews_topic','');
			setTimeout(function(){
				lazyInitEditor('#addNews_content','');
				
			},0);
//			/initCkeditor('addNews_content','',function(){});
		}
	}
}();
$(function(){itsm.news.addNews.init()})